package de.in.tum.msspp.Logger;

import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;

public class Accelerometer implements SensorEventListener{

	private float[] xyzAcceleration = new float[3];
	private double acceleration;
	
	public Accelerometer(SensorManager sensorManager){
        Sensor accSensor = sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER).get(0);//Get Acc. Sensor
        sensorManager.registerListener(this, accSensor, SensorManager.SENSOR_DELAY_GAME);//Register to listen to SensorService
        acceleration = 0;
	}
	
	@Override
	public void onAccuracyChanged(Sensor arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onSensorChanged(SensorEvent event) {
		xyzAcceleration = event.values;
		acceleration = Math.sqrt(event.values[0]*event.values[0]
								+event.values[1]*event.values[1]
								+event.values[2]*event.values[2]);
			
	}
	
	
	
	public double getAcceleration() {
		return acceleration;
	}
	
	public float[] getXyzAcceleration() {
		return xyzAcceleration;
	}

}
